
Rem
	Strip whitespace (or other characters) from the end of a string
	
	@note		I tried to optimize the speed of this function ( notice the use of substr only once )
			Other than that, cnt2 was also initialized once instead of every pass through the for loop
	@author	Nicholas Grant
	@updatedby	
	
	@param	string	str
	@param	string	charlist = ""
	
	@variable	string[]	excludedCharlistSplits
	@variable	integer	notExcludedCharCount
	@variable	integer	cnt
	@variable	integer	cnt2
	@variable	integer	stringLength
	
	@return	string
EndRem
Function rtrim:String( str:String, charlist:String = "" )
	
	Local excludedCharlistSplits:String[];
	Local notExcludedCharCount:Int = 0;
	Local cnt:Int = 0;
	Local cnt2:Int = 0;
	Local stringLength:Int = str.Length;
	
	If ( charlist = "" )
		charlist = " ~t~n~r~0" + Chr(11);
	End If
	
	excludedCharlistSplits = str_split( charlist );
	cnt = str.Length;
	While ( cnt )
		
		For cnt2 = 0 To excludedCharlistSplits.Length - 1
			
			If ( str[cnt-1..cnt][0] = excludedCharlistSplits[cnt2][0] )
				stringLength :- 1;
			Else
				notExcludedCharCount :+ 1;
			End If
			
		Next
		
		cnt :- 1;
		
		If ( notExcludedCharCount = excludedCharlistSplits.Length )
			cnt = 0;
		End If
		
		notExcludedCharCount = 0;
		
	Wend
	str = substr( str, 0, stringLength );
	Return str;
	
End Function